<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
       div{
        width: 100px;
        height: 100px;
        background: lightcoral;
        margin-top: 30px;
        }
    </style>
</head>
<body>
    <!-- 小思考：按钮 点击之后 显示或者隐藏一个div -->
    <button class="btn">点击产生效果</button>
    <div class="box"></div>
    <script>
        var mybtn=document.getElementsByClassName("btn")[0];
        var div=document.getElementsByClassName("box")[0];
        var flag=true;
        mybtn.onclick = function(){
            flag=!flag;
            if(flag==true){
               div.style.display="block";
            }else{
               div.style.display="none";
            }
        }
    </script>
</body>
</html>